import { useLocation, useNavigate, useRoutes } from 'react-router-dom'
import { useEffect } from 'react'
import { message } from 'antd'
import { Outlet } from 'react-router-dom'
const BeforeRouterEnter = () => {
  const navgateTO = useNavigate()
  const location = useLocation()
  let token = localStorage.getItem('token')
  useEffect(() => {
    if (location.pathname === '/login' && token) {
      message.success('您已经登录！')
      return navgateTO('/page')
    }
    if (location.pathname !== '/login' && !token) {
      message.error('您还未登录！')
      return navgateTO('/login')
    }
  })
  return <Outlet/>
}
export default BeforeRouterEnter
